<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>

<!DOCTYPE html>
<html>
<head>
    <jsp:include page="/WEB-INF/jsp/include/head.jsp"/>
</head>
<body>
<ol class="breadcrumb">
    <li><strong>当前位置： </strong>标准化管理</li>
    <li class="active">专家管理</li>
</ol>
<%--String expertName,--%>
<%--String idCard,--%>
<%--@DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday,--%>
<%--Short education,--%>
<%--Short outLander,--%>
<%--Integer assessCount,--%>
<%--String certificateTypeId,--%>
<%--@RequestParam(value = "majorTypeIdList[]", required = false) List<String> majorTypeIdList,--%>
<%--Integer offset,--%>

<div class="panel panel-info">
    <div class="panel-heading">
        <h3 class="panel-title selectslid" style="display: inline-block">查询</h3>
        <shiro:hasPermission name="expertInfo:adminEdit:edit">
            <a role="button"  style="float: right" class="btn btn-default btn-xs btn-success"
               onclick="downLoadExcel(this)"><span class="glyphicon glyphicon-export"></span>&nbsp;导出专家&nbsp</a>
            <span style="float: right;">&nbsp;&nbsp;&nbsp;</span>
            <a role="button" style="float: right;" class="btn btn-default btn-xs btn-success"
               href="expertInfo/adminEdit/uploadExpertInfo/index"><span class="glyphicon glyphicon-log-in"></span>&nbsp;导入专家&nbsp</a>
            <span style="float: right;">&nbsp;&nbsp;&nbsp;</span>
            <a role="button" id="btn_add" style="float: right" class="btn btn-default btn-xs btn-success"
               href="javaScript:;"><span class="glyphicon glyphicon-plus-sign"></span>&nbsp;添&nbsp;加&nbsp;</a>


        </shiro:hasPermission>
    </div>
    <div class="panel-body">
        <form id="form_search" class="form-horizontal row">
            <div class="form-group col-sm-4 ">
                <label class="control-label col-sm-4 ">专家姓名：</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" name="expertName">
                </div>
            </div>

            <%--<div class="form-group col-sm-4 ">--%>
                <%--<label class="control-label col-sm-4 ">身份证号：</label>--%>
                <%--<div class="col-sm-8">--%>
                    <%--<input type="text" class="form-control  " name="idCard">--%>
                <%--</div>--%>
            <%--</div>--%>



            <div class="form-group col-sm-4">
                <label class="col-sm-4 control-label">有效期至：</label>
                <div class="col-sm-8">
                    <div class="input-group date form_date timeInput">
                                                <span class="input-group-addon"><span
                                                        class="glyphicon glyphicon-calendar"></span></span>
                        <input class="form-control " type="text" name="certificateValidDate" placeholder="证书有效期至">
                    </div>
                </div>
            </div>

            <div class="form-group col-sm-4">
                <label class="col-sm-4 control-label">出生日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date form_date timeInput">
                                                <span class="input-group-addon"><span
                                                        class="glyphicon glyphicon-calendar"></span></span>
                        <input class="form-control " type="text"
                               name="birthday">
                        <span class="input-group-addon"><span>之前</span></span>
                    </div>
                </div>
            </div>

            <div class="form-group col-sm-4 ">
                <label class="col-sm-4 control-label">所属单位：</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control  " name="affiliate">
                </div>
            </div>

            <div class="form-group col-sm-4 ">
                <label class="col-sm-4 control-label">是否外省：</label>
                <div class="col-sm-8">
                    <select class="form-control " id="outLander" name="outLander">
                        <option value="">&nbsp;</option>
                    </select>
                </div>
            </div>


            <div class="form-group col-sm-4 ">
                <label class="col-sm-4 control-label">证书类型：</label>
                <div class="col-sm-8">
                    <select class="form-control " multiple id="certificateTypeIdList" name="certificateTypeIdList">
                        <option value="">&nbsp;</option>
                    </select>
                </div>
            </div>


            <div class="form-group col-sm-4 ">
                <label class="col-sm-4 control-label">评审次数：</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" name="assessCount" placeholder="今年评审次数">
                </div>
            </div>

            <div class="form-group col-sm-8">
                <label class="control-label col-sm-2 ">专　　业：&nbsp;</label>
                <div class="col-sm-8">
                    <input type="text" id="zTreeDisplayInput" class="form-control" style="z-index: 100" readonly/>

                    <div id='zTreeContent' style="display: none; position: relative; height: 0px;z-index: 100">
                        <div class="input-group">
                            <input type="text" class="form-control input-sm" id="input_search">
                            <div class="input-group-btn">
                                <button class="btn btn-default btn-sm btn-success " id="btn_tree_search"
                                        type="button"><i class="glyphicon glyphicon-search"></i>&nbsp;搜&nbsp;索
                                </button>
                            </div>
                        </div>
                        <div style="background-color: #f5f5f5;border: 1px solid #ccc">
                            <div style="overflow-y:auto; overflow-x:auto; max-height: 350px; ">
                                <ul id="zTree" class="ztree"></ul>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-2">
                    <button id="btn_search" type="button" class="btn btn-default"><span
                            class="glyphicon glyphicon-search"></span>&nbsp;查&nbsp;询&nbsp;</button>
                </div>
            </div>
        </form>

    </div>
</div>


<table id="table_data"></table>


<div class="modal fade" id="modal_iframe">
    <div class="modal-dialog  modal-xlg ">
        <div class="modal-content ">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">专家信息</h4>
            </div>
            <div id="div_iframe" class="modal-body" style="padding:10px;">
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<div class="modal fade" id="modal_ajax">
    <div class="modal-dialog  modal-lg ">
        <div class="modal-content ">
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<jsp:include page="/WEB-INF/jsp/include/footer.jsp"/>


<script>
    var lastValue = "", treeId = "zTree", nodeList = [];
    function searchNode(newValue) {
        if (lastValue == newValue) {
            return;
        } else {
            lastValue = newValue;
        }
        var zTree = $.fn.zTree.getZTreeObj(treeId);
        updateNodes(false, nodeList, zTree);
        nodeList = zTree.getNodesByParamFuzzy("name", newValue);
        console.log(nodeList);
        updateNodes(true, nodeList, zTree);

        var parents = new Set(nodeList);
        $.each(nodeList, function (i, v) {
            get_parents(v, parents);
            $.each(zTree.transformToArray(v), function (i1, v1) {
                parents.add(v1);
            });
        });
        var allNodes = zTree.transformToArray(zTree.getNodes());
        zTree.hideNodes(allNodes);
        parents.forEach(function (item, sameItem, parents) {
            zTree.showNode(sameItem);
        });
    }


    function get_parents(zTreeNode, parents) {
        if (zTreeNode != undefined) {
            parents.add(zTreeNode);
            var pNode = zTreeNode.getParentNode();
            get_parents(pNode, parents)
        }
    }


    function updateNodes(highlight, nodes, zTree) {
        for (var i = 0, l = nodes.length; i < l; i++) {
            nodes[i].highlight = highlight;
            zTree.updateNode(nodeList[i]);
        }
    }

    function getFontCss(treeId, treeNode) {
        return (treeNode.highlight) ? {color: "#A60000", "font-weight": "bold"} : {
            color: "#333",
            "font-weight": "normal"
        };
    }

</script>

<script>

    var selectTree = new ApmZTreeUtil(
            $("#zTreeDisplayInput"),
            $("#zTreeContent"),
            $("#zTree")
    ), setting = {
        check: {
            enable: true,
            checkboxType: {"Y": "", "N": ""}
        },
        view: {
            dblClickExpand: false,

            fontCss: getFontCss


        },
        data: {
            simpleData: {
                enable: true
            }
        },
        async: {
            enable: true,
            url: "dictionary/publicOpen/majorType"
        },
        callback: {
            beforeClick: selectTree.beforeClick,
            onCheck: selectTree.onCheck,
            onAsyncSuccess: selectTree.onCheck
        }
    };
    $("#zTreeDisplayInput").on('click', function () {
        selectTree.showMenu();
    });
    $.fn.zTree.init($("#zTree"), setting);

    $("#btn_tree_search").click(function () {
        var newValue = $("#input_search").val();
        searchNode(newValue);


    });

</script>
<script>
    var $table_data = $('#table_data');
    $("#btn_search").click(function () {
        $table_data.bootstrapTable('refresh');
    });
    $table_data.bootstrapTable({
        url: 'expertInfo/adminEdit/select',
        striped: true,
        cache: false,
        sidePagination: 'server',
        method: 'post',
        contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
        pageSize: 10,
        pageList: [10, 20, 30, 40, 50, 100],
        pageNumber: 1,
        pagination: true,
        queryParams: paramsFun ,
        columns: [
            {
                formatter: function (value, row, index) {
                    return index + 1
                }
            },
            {
                field: 'name',
                title: '姓名',
                events: 'events',
                formatter: function (value, row, index) {
                    return [
                        '<a  class="nameClick" href="javascript:;" style="text-decoration: none ;display: block;width: 60px">' + value + '</a>'
                    ].join('');
                }

            },
            {
                field: 'idCard',
                title: '身份证号'

            }, {
                field: 'phone',
                title: '联系方式'

            }, {
                field: 'birthday',
                title: '出生日期',
                formatter: function (value, row, index) {
                    return $.Helper.dataTimeHelper.int2DateString(value)

                }
            },
            {
                field: 'outLander',
                title: '是否省外',
                formatter: function (value, row, index) {
                    return $.sysPlugin.ifElse(value, $.sysPlugin.enumeration.outLander)
                }
            },
            {
                field: 'expertCertificateList',
                title: '专家类型',
                formatter: function (value, row, index) {
                    var s = '';
                    $.each(value, function (i, v) {
                        s += v.itemType.name + '：' + v.grade + '；';
                    });
                    if (s.length > 0) {
                        s = s.substr(0, s.length - 1);
                    }
                    return s;
                }

            },
            {
                field: 'expertCompany',
                title: '单位名称',
                formatter: function (value, row, index) {
                    return value && value.name;
                }
            },
            {
                field: 'expertCompany',
                title: '所属单位',
                formatter: function (value, row, index) {
                    return value && value.affiliate;
                }
            },
            {
                field: 'expertCompany',
                title: '单位地址',
                formatter: function (value, row, index) {
                    return value && value.address;
                }
            },
            {
                field: 'assessCount',
                title: '评审次数'
            }
        ]
    });




    window.events = {
        'click .nameClick': function (e, value, row, index) {
            var s = '<iframe  src="expertInfo/adminEdit/expertInfoFrame?id=' + row.id + '" style="padding-top: 0px;" width=100% height=450 frameBorder=0 scrolling=no></iframe>'
            $("#div_iframe").html(s);
            $('#modal_iframe').modal({backdrop: 'static', keyboard: false, show: true});
        }
    };

    function  paramsFun(params) {
        $.extend(params, $("#form_search").serializeObject());
        if (params['certificateTypeIdList']&&!params['certificateTypeIdList'].push) {
            params['certificateTypeIdList'] = [params['certificateTypeIdList']];
        }
        params.majorTypeIdList = getTreeLeafIdList();
        return params
    }

    function getTreeLeafIdList() {
        var treeObj = $.fn.zTree.getZTreeObj("zTree");
        var nodes = treeObj.getCheckedNodes(true);
        var leafIds = new Array();
        for (var i = 0; i < nodes.length; i++) {
            if (!nodes[i].isParent)
                leafIds.push(nodes[i].id);
        }
       return leafIds;
    }




    function downLoadExcel(is){
       var s= $("#form_search").serialize()+"&majorTypeIdList="+getTreeLeafIdList().toString();
        $(is).attr("href",'expertInfo/adminEdit/exportExcel?'+s) ;
    }

    $("#btn_add").click(function () {
        $('#modal_ajax').modal({
            backdrop: 'static',
            keyboard: false,
            show: true,
            remote: 'expertInfo/adminEdit/expertBase/editDlg'
        });
    });


    $.sysPlugin.initSelect2($("#certificateTypeIdList"), {
        url: 'dictionary/publicOpen/certificateTypeAll',
        multiple:true,
    });

    $.sysPlugin.initSelect2($("#outLander"), {
        data: $.sysPlugin.enumeration.outLander
    });
    //
    // $.sysPlugin.initSelect2($("#education"), {
    //     data: $.sysPlugin.enumeration.education
    // });

    $.sysPlugin.initDateTimeInput();
    $.sysPlugin.clearModalRemoveData("modal_ajax");
</script>
</body>
</html>
